package cmd

import (
	"github.com/shirou/gopsutil/process"
	"github.com/spf13/cobra"
)

func killPro(proc *process.Process, er chan<- error) {
	err := proc.Kill()
	er <- err
}

//TODO check process
/*func chkPro() {
	var rProcs *process.Process
	processes, _ := process.Processes()
	for _, p := range processes {
		//name, _ := p.Exe()
		//logger.Info("process name :%s", name)
		if name, _ := p.Exe(); strings.Count(name, "openresty") > 0 {
			rProcs = p
			break
		}
	}
	if rProcs == nil {
		logger.Warn("Not find the process openresty")
		return
	}
	return rProcs
}*/

func _0Stop() *cobra.Command {
	var stopCmd = &cobra.Command{
		Use:     "stop",
		Version: "v0.0.1",
		Short:   UsageGenConf,
		Long:    UsageGenConf,
		Run: func(cmd *cobra.Command, args []string) {

			//ch1 := make(chan error)
			//go killPro(rProcs, ch1)
			//go chkPro()
			//err := <-ch1
			//if err != nil {
			//	log.Fatalf("Stop the process failed!<pid=%d>", rProcs.Pid)
			//}
			//logger.Info("Kill process nginx suc!")
		},
	}
	return stopCmd
}
